package com.atguigu.spring.service.impl;

import com.atguigu.spring.event.ProductOnSaleEvent;
import com.atguigu.spring.service.api.ProductService;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {
    
    public void onSale(Integer productId) {
        System.out.println("产品上架：" + productId + " " + Thread.currentThread().getName());
    }

    public void putIntoCache(Integer productId) {
        System.out.println("产品进入缓存：" + productId);
    }

    public void putIntoSearch(Integer productId) {
        System.out.println("产品进入搜索引擎：" + productId);
    }

    public void putIntoAdQueue(Integer productId) {
        System.out.println("产品进入广告队列：" + productId);
    }

    public void pushToGuest(Integer productId) {
        System.out.println("产品推送潜在客户：" + productId);
    }

    @EventListener
    @Async
    public void putIntoCacheListener(ProductOnSaleEvent event) {
        System.out.println("@产品进入缓存：" + event.getProductId() + " " + Thread.currentThread().getName());
    }

    @EventListener
    @Async
    public void putIntoSearchListener(ProductOnSaleEvent event) {
        System.out.println((10 / 0) + "@产品进入搜索引擎：" + event.getProductId() + " " + Thread.currentThread().getName());
    }

    @EventListener
    @Async
    public void putIntoAdQueueListener(ProductOnSaleEvent event) {
        System.out.println("@产品进入广告队列：" + event.getProductId() + " " + Thread.currentThread().getName());
    }

    @EventListener
    @Async
    public void pushToGuestListener(ProductOnSaleEvent event) {
        System.out.println("@产品推送潜在客户：" + event.getProductId() + " " + Thread.currentThread().getName());
    }
}
